<#include "common.ftl">
/**
 * 项目名：系统项目名称
 * 包名：${entityBean.packageName}
 * 文件名:${entityBean.javaName}
 * 表名: ${entityBean.tableName}
 * 版本信息：1.0.0
 * Copyright (c) 方正移动传媒技术(北京)有限公司-版权所有
 * 
 */
package com.founder.barcode.web.action.toolInfo;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

import com.founder.barcode.web.action.BaseAction;
import com.founder.barcode.framework.dao.support.Page;
import com.founder.barcode.framework.compoment.operamasksui.GridDataModel;
import com.founder.barcode.common.util.UUIDGenerator;
import com.founder.barcode.web.exception.BaseException;
import ${beanPackage}.${beanName};
import ${servicePackage}.I${serviceName};

/**
 * 
 * 类名称:${actionName} 
 * 创建人：
 * 修改人：
 * 修改备注：
 * @version 1.0.0
 * 
 */
@SuppressWarnings("serial") 
public class ${actionName} extends BaseAction<${beanName}> {

   private static Logger logger = LoggerFactory.getLogger(${actionName}.class);
    /**
     * bean对象
     */
    private ${beanName} ${beanObject};
    
    /**
     * service接口注入：
     */
    private ${serviceName} ${serviceObject};
    
    /**
     * 数据模型
     */
    public GridDataModel<${beanName}> model;

    /**
     * 参数封装
     */
    private HashMap<String, Object> map;
    
    /**
     * 功能描述:showAllList显示全部
     * 条件：(这里描述这个方法适用条件 – 可选)
     * @method showAllList
     * @author
     * @throws SQLException
     * @throws BaseException 
     */
    public void showAllList() throws SQLException, BaseException {
        logger.debug("================分页查询==================");
        map = new HashMap<String, Object>();
        if(${beanObject} != null) {
<#list columnBeanList as columnBean>
            map.put("${columnBean.property}",${beanObject}.get${columnBean.property?cap_first}());
</#list>
        }
        //可以在map里自定义查询条件
        super.refreshGridModel();
        model = this.getDataModel();
        String result = JSON.toJSONStringWithDateFormat(model, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteDateUseDateFormat);
        writerToClient(result);
    }
    
    /**
     * 功能描述: 分页查询 
     * 条件：(这里描述这个方法适用条件 – 可选)
     * @method findAllRecord     
     * author：
     * @throws SQLException
     * @throws BaseException
     */
    protected Page findAllRecord() throws BaseException {
        Page page = ${serviceObject}.pageQuery(map, start, limit);
        return page;
    }
      
    /**
     * 功能描述:增加
     * 条件：(这里描述这个方法适用条件 – 可选)
     * @method add     
     * @author     
     * @throws SQLException
     * @throws BaseException
     */
    public void add() throws SQLException, BaseException {
<#list columnBeanList as columnBean>
<#if columnBean.isPrimaryKey>
        ${beanObject}.set${columnBean.property?cap_first}(new UUIDGenerator().generate());
</#if>
</#list>
        ${serviceObject}.save(${beanObject});
        message.setMsg("增加成功！");
        writeJson(message);
    }
     
     /**
     * 功能描述:删除对象
     * 条件：(这里描述这个方法适用条件 – 可选)
     * @method delete     
     * @author     
     * @throws SQLException
     * @throws BaseException
     */
    public void delete() throws SQLException, BaseException {
        ${serviceObject}.delete(${beanObject});
        message.setMsg("删除成功！");
        writeJson(message);
    }
     
    /**
     * 功能描述:修改对象
     * 条件：(这里描述这个方法适用条件 – 可选)
     * @method update     
     * @author     
     * @throws SQLException
     * @throws BaseException
     */
    public void update() throws SQLException, BaseException {
        ${serviceObject}.update(${beanObject});
        message.setMsg("修改成功！");
        writeJson(message);
    }   
     
    /**
     * 功能描述:查询对象
     * 条件：(这里描述这个方法适用条件 – 可选)
     * @method get
     * @author
     * @throws SQLException
     * @throws BaseException
     */    
    public void get() throws SQLException, BaseException {
        ${serviceObject}.get(${beanObject});
        message.setMsg("查询成功！");
        writeJson(message);
    }
    
    /*
     * 查询返回结果集
     * @method select
     * @author     
     * throws SQLException
     * throws BaseException
     */
    public void select() throws SQLException, BaseException {
        List<${beanName}> list = ${serviceObject}.select(${beanObject});
        writeJson(list);
    }
    
    /**
     * 分页方式返回结果集
     * @method pageSelect
     * @author     
     * @throws SQLException
     * @throws BaseException
     */
    public void pageSelect() throws SQLException, BaseException {
        List<ToolInfoPO> list = ${serviceObject}.select(this.toolInfoPO);
        this.model = new GridDataModel<ToolInfoPO>();
        model.setRows(list);
        model.setTotal(list.size());
        String result = JSON.toJSONStringWithDateFormat(model, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteDateUseDateFormat);
        writerToClient(result);
    }
    
    public ${beanName} get${beanObject?cap_first}() {
        return ${beanObject};
    }
    
    public void set${beanObject?cap_first}(${beanName} ${beanObject}) {
        this.${beanObject} = ${beanObject};
    }
    
    public ${serviceName} get${serviceObject?cap_first} () {
        return ${serviceObject} ;
    }
    
    public void set${serviceObject?cap_first} (${serviceName} ${serviceObject} ) {
        this.${serviceObject}  = ${serviceObject} ;
    }
}